<include file="public/header" />
<body>
<div class="layui-fluid">
  <div class="layui-row">
    <form class="layui-form">
      <div class="layui-form-item">
        <label class="layui-form-label">分组管理</label>
        <div class="layui-input-block" style="width: 300px;">
          <select name="group_code"  lay-verify="required">
            <foreach name="group_code"  item="vo">
              <option value="{$key}"  <if condition="$info.group_code eq $vo">selected</if>>{$vo}</option>
            </foreach>

          </select>
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">名称<span style="color: red;">(必填)</span></label>
        <div class="layui-input-block">
          <input type="text" name="name"  style="width: 200px"  lay-verify="required"  value="{$info.name}" autocomplete="off" placeholder="" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">描述<span style="color: red;">(必填)</span></label>
        <div class="layui-input-block">
          <input type="text" name="description"  style="width: 200px"    value="{$info.description}" autocomplete="off" placeholder="" class="layui-input">
        </div>
      </div>
<!--      <div class="layui-form-item">-->
<!--        <label class="layui-form-label">路由controller@action<span style="color: red;">(必填)</span></label>-->
<!--        <div class="layui-input-block">-->
<!--          <input type="text" name="code"  style="width: 200px"    value="{$info.code}" autocomplete="off" placeholder="" class="layui-input">-->
<!--        </div>-->
<!--      </div>-->
      <div class="layui-container">
        <button class="layui-btn" type="button" id="addRow">增加一行</button>

        <table class="layui-table">
          <thead>
          <tr>
            <th>权限码controller@action</th>
            <th>操作</th>
          </tr>
          </thead>
          <tbody id="tableBody">
          <!-- 初始行，可以根据需要添加 -->
          <foreach name="info.code" item="vo">
          <tr>
              <td><input type="text" name="code[]" value="{$vo}" class="layui-input"></td>
              <td><button class="layui-btn layui-btn-danger deleteRow">删除</button></td>
          </tr>
          </foreach>
          </tbody>
        </table>
      </div>
      <div class="layui-form-item" >
        <div class="layui-input-block">
          <input type="hidden" name="id" value="{$info.id}">
          <button type="button"  class="layui-btn" lay-submit=""  lay-filter="addEdit">保存</button>
        </div>
      </div>
    </form>
  </div>
</div>
<script>

  layui.use(['form', 'layedit', 'laydate','jquery','upload'], function(){
    var form = layui.form
            ,layer = layui.layer
            , $ = layui.jquery
            , upload = layui.upload
            ,laydate = layui.laydate
            ,inputTags = layui.inputTags
    var layedit = layui.layedit;
    //拖拽上传

      $('#addRow').click(function() {
        var newRow = `
        <tr>
          <td><input type="text" name="code[]" class="layui-input"></td>
          <td><button class="layui-btn layui-btn-danger deleteRow">删除</button></td>
        </tr>
      `;
        $('#tableBody').append(newRow);
      });

      $(document).on('click', '.deleteRow', function() {
       $(this).closest('tr').remove();
       });




    form.on('submit(addEdit)', function(data){
      $.post($('form').attr('action'),data.field,function(data){
        if(data.code == 200){
          layer.msg(data.msg);
          setTimeout(function () {
            window.history.back();
          },2000)
          xadmin.close();
          xadmin.father_reload();
        }else {
          layer.msg(data.msg);
        }
      });
      return false;
    });
  });

</script>
</body>

</html>
